<template>
	<view>
		<z-paging v-model="list" ref="paging" @query="queryList" show-refresher-when-reload>
			<zixun-list-item v-for="(item,index) in list" :key="item.id" :item='item'></zixun-list-item>
		</z-paging>
		<uni-fab horizontal="right" v-if="isRoleAdmin()" @click="information_publish"></uni-fab>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue';
	import {
		onLoad
	} from "@dcloudio/uni-app"
	import {
		isRoleAdmin
	} from '@/utils/role.js'

	const type = ref(null)

	onLoad((e) => {
		type.value = e.type
		const map = {
			"ZX": "报考资讯",
			"ZN": "报考指南",
			"DG": "报考大纲"
		};
		let title = map[type.value];
		uni.setNavigationBarTitle({
			title
		})
		console.log('type', type.value);
	})

	const db = uniCloud.importObject("consultObj", {
		customUI: true
	});

	const paging = ref(null)
	// v-model绑定的这个变量不要在分页请求结束中自己赋值，直接使用即可
	const list = ref([])

	// @query所绑定的方法不要自己调用！！需要刷新列表数据时，只需要调用paging.value.reload()即可
	const queryList = (pageNo, pageSize) => {
		db.getList((pageNo - 1) * pageSize, pageSize, type.value).then(res => {
			paging.value.complete(res.data);
		}).catch(res => {
			paging.value.complete(false);
		})
	}

	function information_publish() {
		uni.navigateTo({
			url: '/pages/index/baokaozixun/information_publish?type=' + type.value
		})
	}

	uni.$on('information_change', () => {
		if (paging.value) {
			paging.value.refresh()
		}
	})
</script>

<style lang="scss">
	page {
		background: $me-color-background;
	}
</style>

<style lang="scss" scoped>

</style>